
public class Util {

	/**
	 * Reform RGB
	 * @param r
	 * @param g
	 * @param b
	 * @return RGB in a single int.
	 */
	public static int setRGB(int r, int g, int b) {
		return 0xFF000000 | r << 16 | g << 8 | b;
	}
	
	public static int addAlpha(int alpha, int rgb) {
		return alpha << 24 | rgb;
	}
	
	public static int setRGBA(int r, int g, int b, int a)
	{
		return a << 24 | r << 16 | g << 8 | b;
	}
	/**
	 * Get red component of ARGB pixel.
	 */
	public static int getR(int pixel) {
		return (pixel >> 16) & 0xff;
	}

	/**
	 * Get green component of ARGB pixel.
	 */
	public static int getG(int pixel) {
		return (pixel >> 8) & 0xff;
	}

	/**
	 * Get blue component of ARGB pixel.
	 */
	public static int getB(int pixel) {
		return pixel & 0xff;
	}

	public static int getA(int pixel)
	{
		return (pixel >> 24) & 0xff;
	}

	/**
	 * Return sum of RGB components.
	 */
	public static int getRGBsum(int pixel)
	{
		return ((pixel >> 16) & 0xff) +
			   ((pixel >> 8) & 0xff) +
			   ((pixel) & 0xff); 
	}

	/**
	 * Return average of RGB components.
	 */
	public static int getRGBavg(int pixel)
	{
		return (((pixel >> 16) & 0xff) +
			   ((pixel >> 8) & 0xff) +
			   ((pixel) & 0xff)) / 3;
	}

	public static int calcualtePixelVis(float importance, float certainty)
	{
		int red = (int)(importance * 255.0f);
		int green = (int)((1.0f - importance) * 255.0f);
		int blue = 0;

		//alpha
		int alpha = (int) (255.0f * certainty);

		p.print(red + " " + green + " " + blue);
		return setRGBA(red, green, blue, alpha);

	}

}
